﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WABDCUI
{
    public partial class RecitePanel : UserControl
    {
        public List<Word> words;
        public List<int> status;    //1=OK, -1=Cancel
        public int nOk;
        public int nCancel;
        public int current;

        public RecitePanel()
        {
            InitializeComponent();
        }

        new public void Show()
        {
            current = 0;
            this.status = new List<int>();
            for (int i = 0; i < this.words.Count; i++)
            {
                this.status.Add(0);
            }
            nOk = 0;
            nCancel = 0;
            showWord();
            base.Show();
        }

        private void showWord()
        {
            Word w = words[current];
            this.labSpelling.Text = w.Spelling;
            this.labPronunciation.Text = String.Format("/{0}/", w.Pronunciation);
            this.labDescription.Text = w.Description;

            this.labProcess.Text = String.Format("{0}/{1}", current + 1, this.words.Count);

            switch (this.status[current])
            {
                case  1: this.labSpelling.ForeColor = System.Drawing.Color.Green; break;
                case -1: this.labSpelling.ForeColor = System.Drawing.Color.Red; break;
                default: this.labSpelling.ForeColor = System.Drawing.Color.Blue; break;
            }
        }

        private void prev()
        {
            if (current > 0)
            {
                current--;
                showWord();
            }
        }

        private void next() 
        {
            if (current < this.words.Count - 1)
            {
                current++;
                showWord();
            }
        }

        private void btnAddNewWord_Click(object sender, EventArgs e)
        {
            if (this.status[current] == -1)
            {
                //do nothing
            }
            else
            {
                this.labSpelling.ForeColor = System.Drawing.Color.Red;
                this.nCancel++;
                if (this.status[current] == 1)
                {
                    this.nOk--;
                }
                this.status[current] = -1;
            }
        }

        private void cbShowPronunciation_CheckStateChanged(object sender, EventArgs e)
        {
            if (this.cbShowPronunciation.Checked)
            {
                this.labPronunciation.Show();
            }
            else
            {
                this.labPronunciation.Hide();
            }
        }

        private void cbDescription_CheckStateChanged(object sender, EventArgs e)
        {
            if (this.cbDescription.Checked)
            {
                this.labDescription.Show();
            }
            else
            {
                this.labDescription.Hide();
            }
        }

        private void cbSpelling_CheckStateChanged(object sender, EventArgs e)
        {
            if (this.cbSpelling.Checked)
            {
                this.labSpelling.Show();
            }
            else
            {
                this.labSpelling.Hide();
            }
        }

        private void RecitePanel_Click(object sender, EventArgs e)
        {
            Rectangle rect = Screen.PrimaryScreen.WorkingArea;
            if (MousePosition.X < rect.Right / 2)
            {
                prev();
            }
            else
            {
                next();
            }
        }



    }
}
